#ifndef SERVER_H
#define SERVER_H

#include "bitmap.h"
#include "syscall.h"
#include "client.h"

//DATA

const int MAX_CLIENTS = 5;

extern BitMap *freeServerLockBmp;
extern BitMap *freeServerCVBmp;
extern BitMap *freeServerMVBmp;

extern ServerLock *serverLocks[MAX_LOCKS];		/* the table of locks */
extern ServerCV *serverConditions[MAX_CVS];	/* the table of conditions */
extern ServerMV *serverMonitors[MAX_MVS];		/* the table of monitors */

extern PacketHeader sOutPktHdr, sInPktHdr;
extern MailHeader sOutMailHdr, sInMailHdr;

extern int myMachineID;

//FUNCTIONS
void Server();

int compareStrings(char* char1, char* char2);

int LockCreate_Server(char* lockName, int ownerMachID);

int LockAcquire_Server(char* lockName, int ownerMachID, int ownerMailNum);

int LockRelease_Server(char* lockName, int ownerMachID, int ownerMailNum);

int LockDelete_Server(char* lockName, int machID, int mailNum);

int CVCreate_Server(char *cvName, int ownerMachID);

int CVWait_Server(char *cvName, char *lockName, int machID, int ownerMailbox);

int CVSignal_Server(char *cvName, char* lockName, int machID);

bool CVBroadcast_Server(char *cvName, char* lockName, int machID);

bool CVDelete_Server(char *cvName, int machID);

int MVCreate_Server(char *mvName, int machID, int arrSize);

int* MVGet_Server(char *mvName, int machID, int arrIndex);

int MVSet_Server(char *mvName, int machID, int arrIndex, int newVal);

int MVDelete_Server(char *mvName, int machID);

int doYouHaveLock(char* elementName, int type);

int doYouHaveCV(char* elementName, int type);

int doYouHaveMV(char* elementName, int type);

int doIHaveLock(char* elementName);

int doIHaveCV(char* elementName);

int doIHaveMV(char* elementName);

int DYHResponse(char* name, int type, bool response);

int error();
#endif
